const apiBaseUrl = 'https://client-api.bfhldd28.com';

export const request = (url, data = {}, method = "GET") => {
	//登录不显示Loading
	if (url != '/login/wechat-webpage') {
		uni.showLoading({
			title: ''
		})
	}

	const _url = apiBaseUrl + url;
	return new Promise(function(resolve, reject) {
		uni.request({
			url: _url,
			data: data,
			method: method,
			header: {
				'Content-Type': 'application/json',
				'Authorization': uni.getStorageSync('access_token')
			},
			success: function(request) {
				let res = request.data;
				if (res.code == 20000) {
					resolve(res.data);
				} else if (res.code == 20005) {
					uni.showToast({
						title: res.msg,
						icon: 'error',
						duration: 2000
					});
					reject(res.msg);
				} else if (res.code == 50014) {
					// uni.showToast({
					// 	title: res.msg,
					// 	icon:'error',
					// 	duration:2000
					// });
					uni.redirectTo({
						url: '/pages/index/active'
					});
					reject(res.msg);
				} else {
					reject(res.msg);
				}
				uni.hideLoading();
			},
			fail: function(err) {
				reject(err)
				console.log("failed")
				uni.hideLoading();
			}
		})
	});
};